<?php include_once("../ajax/ajaxReporte.php");
    header("Content-type: application/vnd.ms-excel; name='excel'");
    header("Content-Disposition: filename=TicketExcel.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    
    $id_ticket = $_GET["id_ticket"];
    $desde = $_GET["desde"];
    $hasta = $_GET["hasta"];
        
    function ExportarTicketRep($id_ticket,$desde,$hasta){
        $rep = new ReporteBR();
        $fecha_desde = date_to_stamp($desde);
        $fecha_hasta = date_to_stamp($hasta);
        
        $result = $rep->lstTicket($id_ticket, $fecha_desde, $fecha_hasta);
        
        date_default_timezone_get("America/Lima");
        $fecha = date("d/m/Y - h:i:s A");
        
        $html.="<table>";
        $html.="<tr ><td colspan='2' align='center'><h1>Lista de Tickets</h1></td></tr>";
        $html.="<tr><td ><b>Desde :</b></td><td >".$desde."</td></tr>";
        $html.="<tr><td ><b>Hasta :</b></td><td >".$hasta."</td></tr>";
        $html.="<tr><td ><b>Fecha :</b></td><td >".$fecha."</td></tr>";
        $html.="<tr><td colspan='2'><hr></td></tr>";
        $html.="</table>";
        
        $html.= "<table border='1'>";
        $html.="<tr >";
        $html.="<th >Codigo</th>";
        $html.="<th >Nro. Ticket</th>";
        $html.="<th >CUM</th>";
        $html.="<th >Actividad</th>";
        $html.="<th >Fec. Creación</th>";
        $html.="<th >Fec. Cierre</th>";
        $html.="<th >Usuario</th>";
        $html.="</tr>";
        
        if(sizeof($result)==0){
            $html.="<tr><td colspan=7 align='center'>";
            $html.="No se encontraron registros";
            $html.="</td></tr>";
        }else{
            $count = 0;
            foreach ($result as $res){
                $html.="<tr style='font-family:verdana;font-size:11px;'>";
                $html.="<td align='center'>$res->CODIGO</td>";
                $html.="<td align='center'>$res->ID_TICKET</td>";
                $html.="<td align='center'>$res->ID_MULTA</td>";
                $html.="<td align='center'>$res->ACTIVIDAD</td>";
                $html.="<td align='center'>$res->AUDFECCREACION</td>";
                $html.="<td align='center'>$res->AUDFECMODIFICACION</td>";
                $html.="<td align='center'>$res->USUCREACION</td>";
                $html.="</tr>";
                
                $count++;
            }
        }
        
        $html.="<tr><td colspan='7'><hr></td></tr>";
        $html.="<tr><td colspan='7' ><b>Numero de Registros : </b>$count</td></tr>";
        $html.="</table>";
        
        echo $html;
    }
    
    ExportarTicketRep($id_ticket,$desde,$hasta);
?>
